package com.weixin.paleituo.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.weixin.paleituo.R;
import com.weixin.paleituo.adapter.SelectBuildingRecyclerViewAdapter;
import com.weixin.paleituo.adapter.SelectConnunityMenuRecyclerViewAdapter;
import com.weixin.paleituo.base.BaseActivity;
import com.weixin.paleituo.eventbus.SelectHouseEvent;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 选择房号
 */
public class SelectHouseNumberActivity extends BaseActivity {


    @BindView(R.id.iv_back_activity_basepersoninfo)
    ImageView mIvBackActivityBasepersoninfo;
    @BindView(R.id.tv_title_activity_baseperson)
    TextView mTvTitleActivityBaseperson;
    @BindView(R.id.tv_small_title_layout_head)
    TextView mTvSmallTitleLayoutHead;
    @BindView(R.id.rl_head_root_activity_baseperson)
    RelativeLayout mRlHeadRootActivityBaseperson;
    @BindView(R.id.iv_search_head)
    ImageView mIvSearchHead;
    @BindView(R.id.edit_search_head)
    EditText mEditSearchHead;
    @BindView(R.id.tv_location_city_activity_select_house_number)
    TextView mTvLocationCityActivitySelectHouseNumber;
    @BindView(R.id.recycle_nume_activity_select_house_number)
    RecyclerView mRecycleNumeActivitySelectHouseNumber;
    @BindView(R.id.recycle_content_activity_select_house_number)
    RecyclerView mRecycleContentActivitySelectHouseNumber;
    private SelectConnunityMenuRecyclerViewAdapter mSelectConnunityMenuRecyclerViewAdapter;
    private SelectBuildingRecyclerViewAdapter mSelectBuildingRecyclerViewAdapter;
    private List<String> mStringList2;


    @Override
    protected void initView() {
        setContentView(R.layout.activity_select_house_number);
    }

    public static void myStartActiviyt(Context context) {
        Intent intent = new Intent(context, SelectHouseNumberActivity.class);
        context.startActivity(intent);


    }
    @Override
    protected void initData() {
        super.initData();
        mTvTitleActivityBaseperson.setText("选择单元和房号");
        mEditSearchHead.setHint("请输入房号查询，如1001");

        List<String> stringList=new ArrayList<>();
        stringList.add("全部");
        stringList.add("1单元");
        stringList.add("2单元");
        mSelectConnunityMenuRecyclerViewAdapter = new SelectConnunityMenuRecyclerViewAdapter(this,stringList);
        mRecycleNumeActivitySelectHouseNumber.setLayoutManager(new LinearLayoutManager(this));
        mRecycleNumeActivitySelectHouseNumber.setItemAnimator(new DefaultItemAnimator());

        mRecycleNumeActivitySelectHouseNumber.setAdapter(mSelectConnunityMenuRecyclerViewAdapter);
        mSelectConnunityMenuRecyclerViewAdapter.setOnListener(new SelectConnunityMenuRecyclerViewAdapter.OnListener() {
            @Override
            public void onItemOnClick(int position) {
                mStringList2.clear();
                mSelectConnunityMenuRecyclerViewAdapter.setSelectPosition(position);
                mSelectConnunityMenuRecyclerViewAdapter.notifyDataSetChanged();

                switch (position){
                    case 0:
                        mStringList2.add("1单元 1-1-1001");
                        mStringList2.add("2单元 1-2-1001");
                        break;
                    case 1:
                        mStringList2.add("1单元 1-1-1001");
                        break;
                    case 2:
                        mStringList2.add("2单元 1-2-1001");
                        break;
                }

                mSelectBuildingRecyclerViewAdapter.notifyDataSetChanged();


            }
        });


        mStringList2 = new ArrayList<>();
        mStringList2.add("1单元 1-1-1001");
        mStringList2.add("2单元 1-2-1001");
        mSelectBuildingRecyclerViewAdapter = new SelectBuildingRecyclerViewAdapter(this, mStringList2);
        mRecycleContentActivitySelectHouseNumber.setAdapter(mSelectBuildingRecyclerViewAdapter);
        mRecycleContentActivitySelectHouseNumber.setItemAnimator(new DefaultItemAnimator());
        mRecycleContentActivitySelectHouseNumber.setLayoutManager(new LinearLayoutManager(this));
        mSelectBuildingRecyclerViewAdapter.setOnListener(new SelectBuildingRecyclerViewAdapter.OnListener() {
            @Override
            public void onItemOnClick(int position) {
                EventBus.getDefault().post(new SelectHouseEvent(mStringList2.get(position),4));

                BindHouseActivity.myStartActvity(SelectHouseNumberActivity.this);








            }
        });




    }

    @OnClick(R.id.iv_back_activity_basepersoninfo)
    public void onMIvBackActivityBasepersoninfoClicked() {
        finish();
    }
}
